﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;

public partial class aspnet_admin_bock_Link_CX_Link_Edit : System.Web.UI.Page
{

    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();


    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();


    /// <summary>
    /// id
    /// </summary>
    string id = "";
    public string Cid = "";
    DataTable NewDt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (IsPostBack)
        {
            try
            {
                id = Request.QueryString["id"].Trim();

                PageSave(int.Parse(id));
            }
            catch
            {
                Response.Write("");
            }
        }

        Page.Title = "编辑有情Link";

        PageLand_First();




    }

    /// <summary>
    /// 加载时出现的东东
    /// </summary>
    protected void PageLand_First()
    {
        //link类型
        string CX_link_LX = "";

        try
        {
            
            id = Request.QueryString["id"].Trim();
            int.Parse(id);
            MyDt = TextData.SqlataSet("select * from [CX_link] where CX_link_id=" + id + "").Tables[0];
            CX_link_Name.Text = MyDt.Rows[0]["CX_link_Name"].ToString();

            //link类型
            CX_link_LX = MyDt.Rows[0]["CX_link_LX"].ToString();

            if (CX_link_LX.Trim() == "文字")
            {
                Radio1.Checked = true;
            }

            if (CX_link_LX.Trim() == "图片")
            {
                Radio2.Checked = true;
            }

            NewDt.Columns.Add("东东");
            NewDt.Columns.Add("Conts");
            ShowTree(0);
            CX_Column_id.DataSource = NewDt.DefaultView;
            CX_Column_id.DataTextField = "Conts";
            CX_Column_id.DataValueField = "东东";
            CX_Column_id.DataBind();
            CX_Column_id.SelectedValue = MyDt.Rows[0]["CX_Column_id"].ToString().Trim();


            CX_link_Pic.Text = MyDt.Rows[0]["CX_link_Pic"].ToString();
            CX_link_Cont.Text = MyDt.Rows[0]["CX_link_Cont"].ToString();
            CX_link_Sort.Text = MyDt.Rows[0]["CX_link_Sort"].ToString();
            CX_link_linkUrl.Text = MyDt.Rows[0]["CX_link_linkUrl"].ToString();



        }
        catch//出错后的处理
        {
            MyDt = TextData.SqlataSet("select * from [CX_link]  ").Tables[0];
            CX_link_Name.Text = MyDt.Rows[0]["CX_link_Name"].ToString();

            //link类型
            CX_link_LX = MyDt.Rows[0]["CX_link_LX"].ToString();

            if (CX_link_LX.Trim() == "文字")
            {
                Radio1.Checked = true;
            }

            if (CX_link_LX.Trim() == "图片")
            {
                Radio2.Checked = true;
            }

            NewDt.Columns.Add("东东");
            NewDt.Columns.Add("Conts");
            ShowTree(0);
            CX_Column_id.DataSource = NewDt.DefaultView;
            CX_Column_id.DataTextField = "Conts";
            CX_Column_id.DataValueField = "东东";
            CX_Column_id.DataBind();


            CX_link_Pic.Text = MyDt.Rows[0]["CX_link_Pic"].ToString();
            CX_link_Cont.Text = MyDt.Rows[0]["CX_link_Cont"].ToString();
            CX_link_Sort.Text = MyDt.Rows[0]["CX_link_Sort"].ToString();
            CX_link_linkUrl.Text = MyDt.Rows[0]["CX_link_linkUrl"].ToString();

        }
    }


    protected void PageSave(int id)
    {

        //link类型
        string CX_link_LX = "";
        try
        {

            if (Radio1.Checked == true)
            {
                CX_link_LX = "文字";
            }
            if (Radio2.Checked == true)
            {
                CX_link_LX = "图片";
            }

            if (CX_link_Name.Text.Length < 250 && CX_link_Cont.Text.Length < 3000 && int.Parse(CX_link_Sort.Text.Trim()) <= 99999)
            {

                string sql = "";
                sql = "UPDATE [CX_link]\r\n" +
                    "SET \r\n" +
                    "[CX_link_Name] = '" + CX_link_Name.Text.Trim() + "'\r\n" +
                    ",[CX_link_Sort] ='" + CX_link_Sort.Text.Trim() + "'\r\n" +
                    ",[CX_link_Cont] = '" + CX_link_Cont.Text.Trim() + "'\r\n" +
                    ",[CX_link_LX] = '" + CX_link_LX.Trim() + "'\r\n" +
                    ",[CX_Column_id] = '" + CX_Column_id.SelectedValue.Trim() + "'\r\n" +
                    ",[CX_link_Pic] = '" + CX_link_Pic.Text.Trim() + "'\r\n" +
                    ",[CX_link_linkUrl]= '" + CX_link_linkUrl.Text.Trim() + "'\r\n" +

                    "WHERE [CX_link_id] = " + id + "";

                //Response.Write(sql);

                TextData.SqlDataSave(sql);

                tt.Text = "编辑成功" + CX_link_Name.Text + "成功";


            }
            else
            {
                tt.Text = "输入的编辑为空或超过250个或不存在此关键字";

            }
        }
        catch
        {
            tt.Text = "更新不能执行";
        }


    }


    int ii = 0;
    /// <summary>
    /// 返回菜单显示的HTML代码
    /// </summary>
    /// <param name="select">显示的展次</param>
    /// <returns></returns>
    public void ShowTree(int select)
    {
        string sql;
        int i = 0;
        DataTable MyDt = new DataTable();
        sql = "Select * From CX_Column where CX_Column_LX<>3 and CX_Column_followid =" + select + " order by CX_Column_id desc";
        try
        {

            MyDt = TextData.SqlataSet(sql).Tables[0];//创建DataTable MyDt
        }
        catch (Exception ex)
        {
            TextData.Err(ex.Message);

        }
        for (i = 0; i < MyDt.Rows.Count; i++)//遁环记录集
        {
            if (select == 0)//如果只一有层的话
            {

                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            else
            {
                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            ii = ii + 1;
            ShowTree(int.Parse(MyDt.Rows[i]["CX_Column_id"].ToString()));//调用自己显示菜单ＨＴＭＬ
            ii -= 1;

        }


    }
}
